//
//  StatusCellBottomView.swift
//  Weibo
//
//  Created by 张小东 on 16/1/19.
//  Copyright © 2016年 Mr.Zhang. All rights reserved.
//

import UIKit
import SnapKit

class StatusCellBottomView: UIView {
    @objc private func commentBtnDidClick() {
        let temp = TempViewController()
    // 在页面跳转中 使用的频率非常高 可以代替绝大部分的页面跳转 时候使用的协议代理,block 

        // 在push之前设置 隐藏底部 tabbar
        temp.hidesBottomBarWhenPushed = true
        
         navController()?.pushViewController(temp, animated: true)
    }
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        setupUI()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    private func setupUI() {
        backgroundColor = UIColor.whiteColor()
        addSubview(retweetedBtn)
        addSubview(commentBtn)
        addSubview(likeBtn)
        // 设置约束
        retweetedBtn.snp_makeConstraints { (make) -> Void in
            make.left.top.bottom.equalTo(self)
        }
        commentBtn.snp_makeConstraints { (make) -> Void in
            make.left.equalTo(retweetedBtn.snp_right)
            make.bottom.top.equalTo(self)
            make.width.equalTo(retweetedBtn.snp_width)
        }
        likeBtn.snp_makeConstraints { (make) -> Void in
            make.left.equalTo(commentBtn.snp_right)
            make.bottom.top.equalTo(self)
            make.width.equalTo(commentBtn.snp_width)
            make.right.equalTo(self.snp_right)
        }
        // 实例化分割线
        let sepView1 = lineView()
        
        let sepView2 = lineView()
        
        addSubview(sepView1)
        
        addSubview(sepView2)
        
        let w: CGFloat = 0.5
        let scale: CGFloat = 0.4
        
        sepView1.snp_makeConstraints { (make) -> Void in
            make.left.equalTo(retweetedBtn.snp_right)
            make.centerY.equalTo(self.snp_centerY)
            make.height.equalTo(self.snp_height).multipliedBy(scale)
            make.width.equalTo(w)
            
            sepView2.snp_makeConstraints { (make) -> Void in
                make.left.equalTo(commentBtn.snp_right)
                make.centerY.equalTo(self.snp_centerY)
                make.height.equalTo(self.snp_height).multipliedBy(scale)
                make.width.equalTo(w)
            }
 
        }

        commentBtn.addTarget(self, action: "commentBtnDidClick", forControlEvents: .TouchUpInside)
        
    }
    
    // 添加分割线
    private func lineView() -> UIView {
        let v = UIView()
        v.backgroundColor = UIColor.lightGrayColor()
        return v
    }
    
    
    
    
    // 懒加载子视图
    private lazy var retweetedBtn: UIButton = UIButton(title: "转发", fontSize: 10, color: UIColor.darkGrayColor(), backImageName: nil, imageName: "timeline_icon_retweet")
    private lazy var commentBtn: UIButton = UIButton(title: "评论", fontSize: 10, color: UIColor.darkGrayColor(), backImageName: nil, imageName: "timeline_icon_comment")
    private lazy var likeBtn: UIButton = UIButton(title: "点赞", fontSize: 10, color: UIColor.darkGrayColor(), backImageName: nil, imageName: "timeline_icon_unlike")
}
